package com.suyin.ximoon.plugin.mybatis;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.suyin.ximoon.plugin.mybatis.OrderBy.OrderByType;


/**
 * 
 * mapper 拼接sql的参数类型 具体用法,参照 cn.wch.planc.mybatis.criterion.TestController
 * {@link cn.wch.planc.mybatis.criterion.test.TestControllerTestController} WhereParam的生成 参照 Restriction
 * Sql的Mapper配置，参照cn.wch.planc.map/BaseMapper.xml sql的继承参照 CategoryMapper.xml
 * 
 * @author guo
 * 
 */
public class Criteria implements Serializable {

	 /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String table;

	/**
	 * sql 语句中的 字段集合，如果为empty的话，即为*
	 */
	private List<String> selectColumns = new ArrayList<String>();

	/**
	 * and 或者 or 条件集合 ，用and 或者 or连接
	 */
	private List<Junction> junctions = new ArrayList<Junction>();

	/**
	 * update 或者 inser 的sql时候填充的集合，字段=字段值
	 */
	private List<Column> columns = new ArrayList<Column>();

	/**
	 * 排序集合， 字段 asc/desc
	 */
	private List<OrderBy> orderBys = new ArrayList<OrderBy>();
	
	/**
	 * 排序集合， 字段 asc/desc
	 */
	private List<GroupBy> groupBys = new ArrayList<GroupBy>();


	/**
	 * 关联的表名，这里主要针对关联查询 select * from t1,t2 where t1.xx= t2.xxx 有表名
	 */
	private List<String> joinTables = new ArrayList<String>();
	/**
	 * 这里主要针对关联查询时候的，字段关联 ， select * from t1,t2 where t1.xx= t2.xxx
	 */
	private List<Column> joinColumns = new ArrayList<Column>();
	
	public List<Column> getColumns() {
		return columns;
	}

	public void setColumns(List<Column> columns) {
		this.columns = columns;
	}

	public List<OrderBy> getOrderBys() {
		return orderBys;
	}

	public void setOrderBys(List<OrderBy> orderBys) {
		this.orderBys = orderBys;
	}

	

	 public String getTable() {
	 return table;
	 }
	
	 public void setTable(String table) {
	 this.table = table;
	 }

	 public List<String> getSelectColumns() {
		return selectColumns;
	}

	public void setSelectColumns(List<String> selectColumns) {
			this.selectColumns = selectColumns;
	}


	public List<Junction> getJunctions() {
		return junctions;
	}

	public void setJunctions(List<Junction> junctions) {
		this.junctions = junctions;
	}

	/**
	 * 
	 * 增加筛选条件，默认是 and 连接的
	 * 
	 * @param whereParam
	 *            条件
	 */
	public void add(WhereCondition whereCondition) {
		junctions.add(new Conjunction(whereCondition));
	}

	/**
	 * 
	 * 增加筛选条件集合，默认是 and 连接的
	 * 
	 * @param whereParams
	 *            条件集合
	 */

	public void add(List<WhereCondition> whereConditions) {
		junctions.add(new Conjunction(whereConditions));
	}

	/**
	 * 增加 关联条件 and 后者 or
	 * 
	 * @param junction
	 *            关联条件
	 */
	public void add(Junction junction) {
		junctions.add(junction);
	}

	public void addColumn(String column) {
		this.selectColumns.add(column);
	}


	public void addOrderBy(OrderBy orderBy) {
		this.orderBys.add(orderBy);
	}
	public void addOrderBy(String pro, OrderByType orderType) {
		this.orderBys.add(new OrderBy(pro, orderType));
	}


	public void addColumn(Column column) {
		this.columns.add(column);
	}


	public List<String> getJoinTables() {
		return joinTables;
	}

	public void setJoinTables(List<String> joinTables) {
		this.joinTables = joinTables;
	}

	public List<Column> getJoinColumns() {
		return joinColumns;
	}

	public void setJoinColumns(List<Column> joinColumns) {
		this.joinColumns = joinColumns;
	}

	public void addJoinTable(String table) {
		this.joinTables.add(table);
	}

	public void addJoinColumn(String column1, String column2) {
		this.joinColumns.add(new Column(column1, column2));
	}

	public List<GroupBy> getGroupBys() {
		return groupBys;
	}

	public void setGroupBys(List<GroupBy> groupBys) {
		this.groupBys = groupBys;
	}

	public void addGroupBy(GroupBy groupBy) {
		this.groupBys.add(groupBy);
	}
	public void addGroupBy(String pro) {
		this.groupBys.add(new GroupBy(pro));
	}
	


}
